#!/usr/bin/python
#-*-coding:utf-8-*-

###############################################################
## Name       : mv.py
## Author     : gaojiaming
## Date       : Tue Aug 16 10:27:31 CST 2022
## Description:
##
##
###############################################################

import sys
import os
import re
import argparse

def input_sys():
    if len(sys.argv) > 2:
        from_tc = sys.argv[1]
        to_tc = sys.argv[2]
    else:
        print("Input error")
        sys.exit(0)
    return from_tc, to_tc

def modify_tc(frm, to):
    frm_key = os.path.splitext(frm)[0] #得到sanity_case.sv里的sanity_case
    frm_uc = frm_key.upper() #纯小写
    frm_lc = frm_key.lower() #纯大写，执行的时候把这块注释删了
 
    to_key  = os.path.splitext(to)[0]
    to_uc = to_key.upper()
    to_lc = to_key.lower()
 
    out_file = []
    with open(frm, "r") as handle:
        hd = handle.readlines()
        for line in hd:
            line = line.strip("\n")
            line = re.sub(frm_uc, to_uc, line)
            line = re.sub(frm_lc, to_lc, line)
            out_file.append(line)
    return out_file

def write_list(lst, out):
    with open(out, "w") as handle:
        for line in lst:
            handle.write(line+"\n")

def main():
    from_tc, to_tc = input_sys()
    out_file = modify_tc(from_tc, to_tc)
    write_list(out_file, to_tc)
    os.system("rm {0}".format(from_tc))
    pass

if __name__ == "__main__":
    print("%s is working" % __file__)
    main()
